/**]
 * Created by zhuman on 2017/11/20.
 */
define(function () {
    //设置host
    //var host = window.location.protocol + "//" + '192.168.1.149:8081' + "/ks_manager/";
    var host = window.location.protocol + "//" + '192.168.1.149:8080' + "/ks_manager/";
    //var host = window.location.protocol + "//" + '192.168.1.151:8080' + "/ks_manager/";
    //var host = window.location.protocol + "//" + '193.112.1.174:8088' + "/kaisheng/";
    //var host = window.location.protocol + "//" + 'ksglxt.qhmiqi.com' + "/ksglxt/";
    //var host = window.location.protocol + "//" + '192.168.1.18:8080' + "/ks_manager/";
    localStorage.setItem('host', host);

    /*处理时间对象*/
    var dateFormat = function (adate, format) {
        var year = adate.getFullYear();
        var mouth = (adate.getMonth() + 1 < 10 ? '0' + (adate.getMonth() + 1) : adate.getMonth() + 1);
        var day = adate.getDate() < 10 ? '0' + adate.getDate() : adate.getDate();
        var hour = adate.getHours() < 10 ? '0' + adate.getHours() : adate.getHours();
        var min = adate.getMinutes() < 10 ? '0' + adate.getMinutes() : adate.getMinutes();
        var second = adate.getSeconds() < 10 ? '0' + adate.getSeconds() : adate.getSeconds();

        var newDate = null;
        switch (format) {
            case 'yyyy-mm-dd':
                newDate = year + '-' + mouth + '-' + day;
                break;
            case 'yyyy.mm.dd':
                newDate = year + '.' + mouth + '.' + day;
                break;
            case 'yyyy.mm.dd hh:mm':
                newDate = year + '.' + mouth + '.' + day + ' ' + hour + ':' + min;
                break;
            case 'yyyy-mm-dd hh:mm':
                newDate = year + '-' + mouth + '-' + day + ' ' + hour + ':' + min;
                break;
            case 'yyyy年mm月dd日':
                newDate = year + '年' + mouth + '月' + day + '日';
                break;
            case 'yyyy年mm月dd日 hh:mm':
                newDate = year + '年' + mouth + '月' + day + '日' + ' ' + hour + ':' + min;
                break;
            case 'dd/mm/yyyy':
                newDate = day + '/' + mouth + '/' + year;
                break;
            default:
                newDate = year + '.' + mouth + '.' + day;
                break;
        }
        return newDate;
    };

    var Constant = {
        host: host,
        getNowFormatDate: function () {
            var date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            var hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
            var minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
            var second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = year + seperator1 + month + seperator1 + strDate + ' ' + hour + seperator2 + minute + seperator2 + second;
            return currentdate;
        },
        validate: function (formObj) {
            for (i in formObj) {
                var item = formObj[i];
                if (item == null || item == "") {
                    alert("请填写完整")
                    return false
                }
                if (item.constructor == Array) {
                    for (a in item) {
                        if (item[a] == null || item[a] == "") {
                            alert("请填写完整")
                            return false
                        }
                    }
                }
            }
            return true;
        },

        //获取?前面的字符串
        getBefore: function (obj) {
            if (obj.indexOf("?") != -1) {
                obj = obj.split("?")[0];
                return obj;
            }
        },

        //获取?后面的字符串
        getCaption: function (obj) {
            var index = obj.lastIndexOf("?");
            obj = obj.substring(index + 1, obj.length);
            return obj;
        },


        getUrlParam: function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = top.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return r[2];
            return null; //返回参数值
        },

        //先转码后在获得参数
        getAurlparam: function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = decodeURIComponent(top.location.search).substr(1).match(reg);
            if (r != null) return r[2];
            return null; //返回参数值
            /*}*/
        },


        param: {
            domain: localStorage.getItem('host'),
            ckGuidName: 'pin', //cookie name
            client: "WEB",
            version: "0.0.1",
            pageSize: 10,  // 分页控件默认pageSize
            timeout: 50000  // ajax统一超时设置，默认30s
        },

        /*提示语*/
        str: {
            networkError: '网络错误，请稍后再试！',
            systemError: '系统异常，请稍后再试！',
            emptyError: '请填写完整信息',
            phoneError: '手机号码错误！'
        },

        /*正则匹配*/
        reg: {
            phone: /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/,
            num: /^[0-9]\d*$/,
            bankNo: /^(998801|998802|622525|622526|435744|435745|483536|528020|526855|622156|622155|356869|531659|622157|627066|627067|627068|627069)d{10}$/,
            // 匹配yyyy-mm-dd格式的日期，区间为1900-2099
            isCarid: /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/,
            day: /^(19|20)\d{2}-(1[0-2]|0?[1-9])-(0?[1-9]|[1-2][0-9]|3[0-1])$/,
            email: /^[A-Za-z0-9+]+[A-Za-z0-9\.|-|_+]*\@([A-Za-z0-9\-]+\.)+[A-Za-z0-9]+$/,
            // 匹配正负数，不能为0，小数点后最多两位
            amount: /^(\-)?((0\.(0[1-9]|[1-9]\d?))|([1-9]\d*(\.\d{1,2})?))$/
        },

        //handlebars 注册
        initHandlebars: function (Handlebars) {
            var _this = this;
            Handlebars.registerHelper('permit', function (type, localNetWork, opts) {
                var permissions = Constant.menuPermissions;
                if (localNetWork) {// 内网
                    if (localAreaNetwork) {
                        if (permissions && permissions[type] == 1) {// 有相应权限
                            return opts.fn(this);
                        } else {
                            return opts.inverse(this);
                        }
                    }
                    return opts.inverse(this);
                } else {// 外网
                    if (permissions && permissions[type] == 1) {
                        return opts.fn(this);
                    }
                    return opts.inverse(this);
                }
            });
            Handlebars.registerHelper('enptyVaule', function (value) {
                return Constant.tplHelper.DEAL_WITH_EMPTY_VALUE(value);
            });
            Handlebars.registerHelper('formatDate', function (date, format) {
                return Constant.fn.formatDateAll(date, format);
            });
            Handlebars.registerHelper('thounsandBit', function (num) {
                return Constant.tplHelper.AMOUNT_FORMAT(num);
            });
            Handlebars.registerHelper('valueFormat', function (money) {
                return Constant.fn.valueFormat(money);
            });
            Handlebars.registerHelper('cryptCrad', function (num, type) {
                return Constant.fn.crypt(num, type);
            });
            Handlebars.registerHelper('IF_EQ', function (a, b, options) {// 判断是否等于
                return Constant.tplHelper.IF_EQ(a, b, this, options);
            });
            Handlebars.registerHelper('IF_GT', function (a, b, opts) {//判断是否大于
                return Constant.tplHelper.IF_GT(a, b, this, opts);
            });
            Handlebars.registerHelper('IF_NGT', function (a, b, opts) {//判断是否大于等于
                return Constant.tplHelper.IF_NGT(a, b, this, opts);
            });
            Handlebars.registerHelper('IF_NEQ', function (a, b, opts) {//判断是否不相等
                return Constant.tplHelper.IF_NEQ(a, b, this, opts);
            });
            Handlebars.registerHelper('fee', function (a, b, c) {
                return Constant.tplHelper.fee(a, b, c);
            });
            Handlebars.registerHelper('re', function (a, type, key, loanType, repaymentWay, applyTerm, loanMethod, orderSource) {
                return Constant.tplHelper.re(a, type, key, loanType, repaymentWay, applyTerm, loanMethod, orderSource);
            });
            Handlebars.registerHelper('JArray', function (a) {
                return Constant.tplHelper.JArray(a);
            });
            Handlebars.registerHelper('add', function () {
                var sum = 0;
                if (arguments.length == 0) return sum;        //如果没有参数，退出
                for (var i = 0; i < arguments.length - 1; i++) {
                    arguments[i] = arguments[i] ? arguments[i] : 0;//如果有，就累加
                    sum = sum + arguments[i];
                }
                return Constant.tplHelper.AMOUNT_FORMAT(sum);
            });
            Handlebars.registerHelper('substraction', function () {
                var sum = arguments[0];
                if (arguments.length == 0) return sum;        //如果没有参数，退出
                for (var i = 1; i < arguments.length - 1; i++) {    //如果有，就累减
                    arguments[i] = arguments[i] ? arguments[i] : 0;//如果有，就累减
                    sum = sum - arguments[i];
                }
                return Constant.tplHelper.AMOUNT_FORMAT(sum);
            });
            Handlebars.registerHelper('multiply', function () {
                var sum = 1;
                if (arguments.length == 0) return sum;        //如果没有参数，退出
                for (var i = 0; i < arguments.length - 1; i++) {
                    arguments[i] = arguments[i] ? arguments[i] : 0;//如果有，就累加
                    sum = sum * arguments[i];
                }

                return Constant.tplHelper.AMOUNT_FORMAT(sum);
            });
            //贷后还款明细余款判断
            Handlebars.registerHelper('residue', function (a, b, c, option) {
                a = a ? a : 0;
                b = b ? b : 0;
                c = c ? c : 0;
                if (a + b - c > 0) {
                    return option.fn(this);
                }
                else {
                    return option.inverse(this)
                }
            });
            Handlebars.registerHelper('addAndSub', function (a, b, c) {
                a = a ? a : 0;
                b = b ? b : 0;
                c = c ? c : 0;
                return Constant.tplHelper.AMOUNT_FORMAT(a + b - c);
            });

            Handlebars.registerHelper('expression', function () {
                var exps = [];
                try {
                    //最后一个参数作为展示内容，也就是平时的options。不作为逻辑表达式部分
                    var arg_len = arguments.length;
                    var len = arg_len - 1;
                    for (var j = 0; j < len; j++) {
                        if (!arguments[j] && arguments[j] !== 0) {
                            arguments[j] = 'null';
                        }
                        exps.push(arguments[j]);
                    }
                    var result = eval(exps.join(' '));
                    if (result) {
                        return arguments[len].fn(this);
                    } else {
                        return arguments[len].inverse(this);
                    }
                } catch (e) {
                    throw e;
                }
            });

            //判断他的上一步是否是已拒绝
            Handlebars.registerHelper('lastStepIsRefused', function (a, b, option) {
                //console.log(a.flowList[b + 1])
                var c = a.flowList ? a.flowList : a.nodeList;
                if (c[b + 1]) {
                    if (c[b + 1].type == 2) {
                        return option.fn(this);
                    }
                    else {
                        return option.inverse(this)
                    }
                } else {
                    return option.inverse(this)
                }
            });

            //对url进行unicode转码
            Handlebars.registerHelper('urlUnicode', function (str) {
                console.log(encodeURIComponent(str))
                return encodeURIComponent(str);
            });


            //获取省份
            Handlebars.registerHelper('province', function (str) {
                return str.substr(0, 3);
            });

            //获取城市

            Handlebars.registerHelper('city', function (str) {
                return str.substr(3, 3);
            });


            //获取父级索引
            Handlebars.registerHelper("addOne", function (index) {
                //利用+1的时机，在父级循环对象中添加一个_index属性，用来保存父级每次循环的索引
                this._index = index;
                //返回+1之后的结果
                return this._index;
            });


            //获取索引值后加1
            Handlebars.registerHelper("indexAddOne", function (index) {
                return index + 1;
            });

            //判断图片后缀
            Handlebars.registerHelper("IF_PDF", function (a, b, opts) {// 比较是否相等
                if (_this.fn.getFileType(a) == b) {
                    return opts.fn(this);
                } else {
                    return opts.inverse(this);
                }
            })

            //拿到文件名称
            Handlebars.registerHelper("FN", function (a) {// 比较是否相等
                return _this.fn.getFileName(a);
            })

            Handlebars.registerHelper("chinese", function (a) {// 将数字翻译成繁体中文
                return _this.fn.chinese(a);
            })

            Handlebars.registerHelper("four", function (a, opts) {// 如果不是4的倍数
                if (parseInt(a) % 6 != 1 && a != 1) {
                    return opts.fn(this);
                } else {
                    return opts.inverse(this);
                }
            })

            Handlebars.registerHelper("five", function (a, opts) {// 如果是4的倍数
                if (parseInt(a) % 4 == 1) {
                    return opts.fn(this);
                } else {
                    return opts.inverse(this);
                }
            })
            Handlebars.registerHelper("lastIndex", function (a, b, opts) {// 判断是否是最后一个
                if (a === b.length - 1) {
                    return opts.fn(this);
                } else {
                    return opts.inverse(this);
                }
            })

            Handlebars.registerHelper("NotFirstLast", function (a, b, opts) {// 判断是否是最后一个
                if (a !== 0 && a !== b.length - 1) {
                    return opts.fn(this);
                } else {
                    return opts.inverse(this);
                }
            })

            Handlebars.registerHelper("LastName", function (a) {// 拿到最后一个元素的名字
                return a[a.length - 1].ACT_NAME_;
            })

            Handlebars.registerHelper("isOver", function (a, opts) {// 判断是否是最后一个
                if (a[a.length - 1].type == '0') {
                    return opts.fn(this);
                } else {
                    return opts.inverse(this);
                }
            })

            Handlebars.registerHelper("unpaid", function (a, b, c, d, e, f) {
                for (var i = 0; i < arguments.length - 1; i++) {
                    arguments[i] = arguments[i] ? arguments[i] : 0;//如果有，就累加// 计算贷后未还总额
                }
                return Constant.tplHelper.AMOUNT_FORMAT(a + b + c + d + e - f);
            })

            //减一
            Handlebars.registerHelper("subOne", function (a) {
                return a - 1;
            })

            Handlebars.registerHelper("IF_PDF", function (a, b, opts) {// 比较是否相等
                if (_this.fn.getFileType(a) == b) {
                    return opts.fn(this);
                } else {
                    return opts.inverse(this);
                }
            })

            Handlebars.registerHelper("IF_OVER", function (a, opts) { //贷后结清状态的判断
                if (a === 'checkOrder' || a === 'revisitRecord' || a === 'submitVisit' || a === 'sumbitGathering' || a === 'loanRecord') {
                    return opts.fn(this);
                } else {
                    return opts.inverse(this);
                }
            })

            //出借记录的出借人马赛克
            Handlebars.registerHelper("cover", function(source, reservedNumHalf, opts) {
                if (!source) {
                    return '';
                }

                var finalReservedNumHalf;
                var mask;
                if (source.length === 1) {
                    return source;
                }
                if (source.length === 2) {
                    return '*' + source.substr(source.length - 1);
                }
                if (source.length <= 3) {
                    finalReservedNumHalf = 1;
                    mask = '*';
                } else if (source.length === 4) {
                    finalReservedNumHalf = 2;
                    mask = '**';
                } else {
                    finalReservedNumHalf = reservedNumHalf || 3;
                    mask = '***';
                }
                return source.substr(0, finalReservedNumHalf) + mask + source.substr(source.length - finalReservedNumHalf);
            })
        },

        tplHelper: {
            //吊炸天的东西，复杂的逻辑运算
            expression: function () {
                var exps = [];
                try {
                    //最后一个参数作为展示内容，也就是平时的options。不作为逻辑表达式部分
                    var arg_len = arguments.length;
                    var len = arg_len - 1;
                    for (var j = 0; j < len; j++) {
                        exps.push(arguments[j]);
                    }
                    var result = eval(exps.join(' '));
                    if (result) {
                        return arguments[len].fn(this);
                    } else {
                        return arguments[len].inverse(this);
                    }
                } catch (e) {
                    throw new Error('Handlerbars Helper "expression" can not deal with wrong expression:' + exps.join(' ') + ".");
                }
            },
            re: function (str, type, key, loanType, repaymentWay, applyTerm, loanMethod, orderSource) {
                var rs = str.match(/content=(.*)}/);
                var payBydays = true;
                if (rs) {
                    if (rs.length > 0) {
                        return rs[1]
                    }
                }
                else {
                    if (type === 1) {
                        if (key === 'repayment_way') {
                            for (var i = 0; i < repaymentWay.length; i++) {
                                if (repaymentWay[i].id == str) {
                                    return repaymentWay[i].re_name;
                                }
                            }
                        } else if (key === 'at_id') {
                            for (var i = 0; i < applyTerm.length; i++) {
                                if (applyTerm[i].id == str) {
                                    return applyTerm[i].atName;
                                    payBydays = false;
                                }
                            }
                            if(payBydays){
                                return str + '天';
                            }
                        } else if (key === 'lt_id') {
                            for (var i = 0; i < loanType.length; i++) {
                                if (loanType[i].id == str) {
                                    return loanType[i].ltName;
                                }
                            }
                        } else if (key === 'loan_way') {
                            for (var i = 0; i < loanMethod.length; i++) {
                                if (loanMethod[i].loan_method_id == str) {
                                    return loanMethod[i].name;
                                }
                            }
                        } else if (key === 'os_id') {
                            for (var i = 0; i < orderSource.length; i++) {
                                if (orderSource[i].id == str) {
                                    return orderSource[i].osName;
                                }
                            }
                        } else if (key === 'apply_money' || 'interest') {
                            return str;
                        }
                    }
                    else {
                        return str
                    }
                }
            }
            ,
            JArray: function (str) {
                return JSON.parse(str);
            }
            ,
            // 基础方法
            IF_EQ: function (a, b, data, opts) {// 比较是否相等
                if (a == b) {
                    return opts.fn(data);
                } else {
                    return opts.inverse(data);
                }
            }
            ,
            IF_NEQ: function (a, b, data, opts) {// 比价是否不相等
                if (a != b) {
                    return opts.fn(data);
                } else {
                    return opts.inverse(data);
                }
            }
            ,
            IF_GT: function (a, b, data, opts) {// 比较是否大于
                if (a > b) {
                    return opts.fn(data);
                } else {
                    return opts.inverse(data);
                }
            }
            ,
            IF_NGT: function (a, b, data, opts) {// 比较是否大于等于
                if (a >= b) {
                    return opts.fn(data);
                } else {
                    return opts.inverse(data);
                }
            },
            DEAL_WITH_EMPTY_VALUE: function (value) {// 处理空值字符串
                return (value == null || value == undefined || value == "") ? '--' : value;
            }
            ,
            AMOUNT_FORMAT: function (num) {// 数字千分位分割
                if (num == null || num == 'null') return '--';

                var str = "" + num && (num
                    .toString().indexOf('.') != -1 ? num.toString().replace(/\d{1,3}(?=(\d{3})+\.[元]?)/g, function ($1) {
                    return $1 + ",";
                }) : num.toString().replace(/\d{1,3}(?=(\d{3})+[元]?$)/g, function ($1) {
                    return $1 + ",";
                }));

                //前端显示，加0
                if (str.indexOf('.') > 0 && str.length - str.indexOf('.') < 3)
                    str += '0';
                return str;
            }
            ,
            COMPILE_RATE: function (minRate, maxRate) {// 合并年化收益率
                if (!minRate && !maxRate) return '--';
                if (!minRate && maxRate) return maxRate + '%';
                if (minRate && !maxRate) return minRate + '%';
                var rate = minRate == maxRate ? minRate + '%' : minRate + '%-' + maxRate + '%';
                return rate;
            }
            ,
            UESR_GENDER: function (gender) {// 根据性别返回男生头像或女生头像
                if (gender) {
                    return 'icon-man';
                } else {
                    return 'icon-female';
                }
            }
            ,
            fee: function (fee, type, apply_money) {
                if (type == '1') {
                    return fee
                }
                else if (type == '2') {
                    return this.AMOUNT_FORMAT(apply_money * parseFloat(fee / 100))
                }
            },


        },


        /*获取屏幕宽高*/
        screenWidth: $(window).width(),
        screenHeight: $(window).height(),

        /*页面id，当页面内要跳转时在这里配置*/
        pageId: {},

        /*公共方法*/
        fn: {
            login: function (token) {
                var expiresDate = new Date();
                expiresDate.setTime(expiresDate.getTime() + (43200 * 60 * 1000));
                $.cookie(Constant.param.ckGuidName, token, {expires: expiresDate, path: '/'});
            },
            /** 查找 form表单，将url参数内容填入input中 */
            initForm: function (formId, param) {
                var dom = '%s input,%s select'.replace(/%s/g, formId);
                $(dom).each(function (e) {
                    var id = $(this).attr('id');
                    var val = getUrlParam(id);
                    if (val && id) {
                        $(this).val(val);

                        if (param)
                            param[id] = val;
                    }
                    //@tip：val()这样能处理form的text类型，如果请求参数不对，需要排查是否使用其他方法
                });
            },
            /** 查找 form表单，将input内容填入param中 */
            formParam: function (formId, param) {
                var dom = '%s input,%s select'.replace(/%s/g, formId);
                $(dom).each(function (e) {
                    var name = $(this).attr('id');
                    var val = $(this).val();
                    if (val && name) {
                        param[name] = val;
                    }
                    //@tip：val()这样能处理form的text类型，如果请求参数不对，需要排查是否使用其他方法
                });
                return param;
            },
            validator: function (verify, $error) {// 校验器
                for (var i in verify) {
                    var item = verify[i], value = $.trim(item.value), reg = item.reg, isNeed = item.isNeed;
                    if (isNeed && !value) {
                        // $error.html(item["name"]+"不能为空");
                        Constant.fn.Message('F', item["name"] + "不能为空");
                        return false;
                    }
                    if (value && reg) {
                        if (!reg.test(value)) {
                            // $error.html(item["errorMsg"]);
                            Constant.fn.Message('F', item["errorMsg"]);
                            return false;
                        }
                    }
                }
                // $error.text('');// 清空报错信息
                return true;
            },
            formatDateAll: function (date, format) {
                if (!date) {
                    return '--'
                }

                if (date instanceof Date) {// 把时间对象转化为指定格式时间字符串
                    return dateFormat(date, format);
                } else if (Object.prototype.toString.call(date) === "[object String]") { // 把'yyyy.mm.dd hh:mm'格式转换为其他格式
                    var newDate = null;
                    switch (format) {
                        case 'yyyy-mm-dd':
                            newDate = date.substring(0, 10).replace(/\./g, '-');
                            break;
                        case 'yyyy.mm.dd':
                            newDate = date.substring(0, 10).replace(/\-/g, '.');
                            break;
                        case 'yyyy-mm-dd hh:mm':
                            newDate = date.replace(/\./g, '-');
                            break;
                        case 'yyyy年mm月dd日':
                            newDate = date.substring(0, 10)
                                .replace(/\./, '年')
                                .replace(/\./, '月') + '日';
                            break;
                        case 'yyyy年mm月dd日 hh:mm':
                            newDate = date.substring(0, 10)
                                    .replace(/\./, '年')
                                    .replace(/\./, '月') + '日'
                                + date.substring(10);
                            break;
                        default:
                            newDate = date.substring(0, 10);
                            break;
                    }
                    return newDate;
                } else { // 时间戳转成相应格式的日期
                    return dateFormat(new Date(date), format);
                }
            },
            valueFormat: function (value) {// 处理金额单位
                if (value == null) {
                    return '';
                }
                if (isNaN(value)) {
                    value = parseFloat(value);
                }

                if (value < 10000) {
                    return '' + value;
                } else if (value < 100000000) {
                    return Math.floor(value / 10000) + '万';
                } else {
                    return Math.floor(value / 100000000) + '亿';
                }
            },
            crypt: function (num, type) {// 隐藏银行卡号码或手机号码
                if (!num) return '--';
                var numStr = num.toString();
                switch (type) {
                    case 'bankCardNo':
                        return "**** **** **** " + numStr.substring(numStr.length - 4, numStr.length);
                        break;
                    case 'certNo':
                        return numStr.substring(0, 3) + "***" + numStr.substring(numStr.length - 4, numStr.length);
                        break;
                    default:
                        return numStr.substring(0, 3) + "****" + numStr.substring(7, numStr.length);
                }
            },
            btnStatusManage: {// 管理按钮状态
                disabled: function ($btn, isSetStatus) {
                    if (!$btn || $btn.length < 1) return;
                    if (typeof isSetStatus == 'undefined') {
                        $btn.attr("disabled", "disabled").addClass("disabled");
                    }
                    if (typeof isSetStatus != 'undefined') {
                        if (isSetStatus === false) {
                            $btn.attr("disabled", "disabled").addClass("disabled");
                        }
                    }
                },
                enable: function ($btn) {
                    if (!$btn || $btn.length < 1) return;
                    $btn.removeAttr("disabled").removeClass("disabled");
                },
                isDisabled: function ($btn) {
                    if (!$btn || $btn.length < 1) return false;
                    if ($btn.hasClass("disabled")) {
                        return true
                    }
                    return false
                }
            },

            //表单验证弹出框部分
            timeErr: {time: ''},
            timeSuc: {time: ''},
            timeI: {time: ''},

            animations: function (ele, time) {
                clearTimeout(time.time)
                $('.' + ele).animate({
                    'right': '48px',
                }, 500, function () {
                    time.time = setTimeout(function () {
                        $('.' + ele).css({'right': '-250px'})
                        $('.' + ele).css('display', 'none')
                    }, 3000)
                })
            },
            Message: function (ele, mes) {
                var element = null
                if (ele == 'T') element = 'sucMes'
                else if (ele == 'F') element = 'errMes'
                else if (ele == 'I') element = 'IMes'
                $('.' + element).html(mes)
                if (element == 'errMes') {
                    $('.mesFalse').css('display', 'block')
                    this.animations('mesFalse', this.timeErr)
                }
                if (element == 'sucMes') {
                    $('.mesTrue').css('display', 'block')
                    this.animations('mesTrue', this.timeSuc)
                }
                if (element == 'IMes') {
                    $('.mesI').css('display', 'block')
                    this.animations('mesI', this.timeI)
                }
            },

            //截取文件名后缀
            getFileType: function (str) {
                var index = str.lastIndexOf(".");
                var ext = str.substr(index + 1);
                return ext;
            },

            //获取文件名称
            getFileName: function (str) {
                var pos = str.lastIndexOf("/");
                return str.substring(pos + 1);
            },


            //上传图片是否显示左右箭头初始化
            initScroll: function () {
                $.each($("[id^='gallery']"), function (i, e) {
                    console.log($(e).find('li').length);
                    if ($(e).find('li').length >= 4) {
                        console.log($(e))
                        console.log($(e).parent('.cover').siblings('._pre'));
                        $(e).parent('.cover').siblings('._pre').show();
                        $(e).parent('.cover').siblings('._next').show();
                        $(e).css({
                            width: $(e).find('li').length * 85 + 'px'
                        })
                    } else {
                        $(e).parent('.cover').siblings('._pre').css('display', 'none');
                        $(e).parent('.cover').siblings('._next').css('display', 'none');
                    }
                })

                $('._next').on('click', function () {
                    var left = parseInt($(this).siblings('.cover').find('[attachid]').css('left'));
                    var absLeft = Math.abs(parseInt($(this).siblings('.cover').find('[attachid]').css('left')))
                    if (parseInt($(this).siblings('.cover').find('[attachid]').css('width')) - parseInt($(this).siblings('.cover').css('width')) > absLeft) {
                        $(this).siblings('.cover').find('[attachid]').css({'left': left - 80 + 'px'});
                    }
                })

                $('._pre').on('click', function () {
                    var left = parseInt($(this).siblings('.cover').find('[attachid]').css('left'));
                    if (left < 0) {
                        $(this).siblings('.cover').find('[attachid]').css({'left': left + 80 + 'px'});
                    }
                    if (parseInt($(this).siblings('.cover').find('[attachid]').css('left')) > 0) {
                        $(this).siblings('.cover').find('[attachid]').css({'left': '0px'});
                    }
                })
            },

            //上传文件是否显示左右箭头初始化
            initFileScroll: function () {
                $.each($("[id^='fileGallery']"), function (i, e) {
                    console.log($(e).find('a').length);
                    if ($(e).find('a').length >= 4) {
                        console.log($(e))
                        console.log($(e).parent('.fileCover').siblings('.file_pre'));
                        $(e).parent('.fileCover').siblings('.file_pre').show();
                        $(e).parent('.fileCover').siblings('.file_next').show();
                        $(e).css({
                            width: $(e).find('a').length * 80 + 'px'
                        })
                    } else {
                        $(e).parent('.fileCover').siblings('.file_pre').css('display', 'none');
                        $(e).parent('.fileCover').siblings('.file_next').css('display', 'none');
                    }
                })

                $('.file_next').on('click', function () {
                    var left = parseInt($(this).siblings('.fileCover').find('[fileAttachId]').css('left'));
                    var absLeft = Math.abs(parseInt($(this).siblings('.fileCover').find('[fileAttachId]').css('left')))
                    if (parseInt($(this).siblings('.fileCover').find('[fileAttachId]').css('width')) - parseInt($(this).siblings('.cover').css('width')) > absLeft) {
                        $(this).siblings('.fileCover').find('[fileAttachId]').css({'left': left - 80 + 'px'});
                    }
                })

                $('.file_pre').on('click', function () {
                    var left = parseInt($(this).siblings('.fileCover').find('[fileAttachId]').css('left'));
                    if (left < 0) {
                        $(this).siblings('.fileCover').find('[fileAttachId]').css({'left': left + 80 + 'px'});
                    }
                    if (parseInt($(this).siblings('.fileCover').find('[fileAttachId]').css('left')) > 0) {
                        $(this).siblings('.fileCover').find('[fileAttachId]').css({'left': '0px'});
                    }
                })
            },


            //初始化页面全选功能
            initAllCheck: function () {
                $.each($("input[name='ch_id']"), function (i, e) {
                    var flag = false;
                    $(e).on('click', function () {
                        var _checked = $("input[name='ch_id_all']")
                        var _checkedAll = $("input[name='ch_id']")
                        $.each(_checkedAll, function (ii, ee) {
                            if ($(ee).prop('checked')) {
                                flag = true
                            }
                            else {
                                flag = false
                                return false;
                            }
                        })
                        _checked.prop('checked', flag);
                    })
                })
            },


            /*禹
        input框中转成人民币货币形式
        */
            toRMB: function (number, places, symbol, thousand, decimal) {
                number = number || 0
                places = !isNaN(places = Math.abs(places)) ? places : 2
                symbol = symbol !== undefined ? symbol : '￥'
                thousand = thousand || ','
                decimal = decimal || '.'
                var negative = number < 0 ? '-' : '',
                    i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + '',
                    j = (j = i.length) > 3 ? j % 3 : 0
                return symbol + negative + (j ? i.substr(0, j) + thousand : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : '')
            }
            ,

            /*禹
             *录入订单 编辑订单中人民币形式转成number传给后台
             */
            toNum: function (price) {
                price += ''
                return price.replace(/[^\d\.$]/g, '')//[^]在里面代表非字符的任意字符
            },

            //把数字翻译成中文
            chinese: function (input) {
                var numberValue = new String(Math.round(input * 100));
                var chineseValue = '';
                var String1 = '零壹贰叁肆伍陆柒捌玖';
                var String2 = '万仟佰拾亿仟佰拾万仟佰拾元角分';
                var len = numberValue.length;
                var Ch1;
                var Ch2;
                var nZero = 0;
                var String3;
                if (len > 15) {
                    alert('超出计算范围');
                    return '';
                }
                if (numberValue == 0) {
                    chineseValue = '零元整';
                    return chineseValue;
                }
                String2 = String2.substr(String2.length - len, len);
                for (var i = 0; i < len; i++) {
                    String3 = parseInt(numberValue.substr(i, 1), 10);
                    if (i != (len - 3) && i != (len - 7) && i != (len - 11) && i != (len - 15)) {
                        if (String3 == 0) {
                            Ch1 = '';
                            Ch2 = '';
                            nZero = nZero + 1;
                        }
                        else if (String3 != 0 && nZero != 0) {
                            Ch1 = '零' + String1.substr(String3, 1);
                            Ch2 = String2.substr(i, 1);
                            nZero = 0;
                        }
                        else {
                            Ch1 = String1.substr(String3, 1);
                            Ch2 = String2.substr(i, 1);
                            nZero = 0;
                        }
                    }
                    else {
                        if (String3 != 0 && nZero != 0) {
                            Ch1 = '零' + String1.substr(String3, 1);
                            Ch2 = String2.substr(i, 1);
                            nZero = 0;
                        }
                        else if (String3 != 0 && nZero == 0) {
                            Ch1 = String1.substr(String3, 1);
                            Ch2 = String2.substr(i, 1);
                            nZero = 0;
                        }
                        else if (String3 == 0 && nZero >= 3) {
                            Ch1 = '';
                            Ch2 = '';
                            nZero = nZero + 1;
                        }
                        else {
                            Ch1 = '';
                            Ch2 = String2.substr(i, 1);
                            nZero = nZero + 1;
                        }
                        if (i == (len - 11) || i == (len - 3)) Ch2 = String2.substr(i, 1);
                    }
                    chineseValue = chineseValue + Ch1 + Ch2;
                }
                if (String3 == 0) chineseValue = chineseValue + '整';
                return chineseValue;
            }
        },
    }

    return Constant;
});